package tacticalLayer;

import org.jdom.Element;

import planninglanguage.plans.BasicOperatorPlan;
import util.XMLWriter;
import base.ProxyBot;
import base.WargusGameState;
import base.WargusStateImporter;

public class SimpleTacticalLayer extends TacticalLayer {

	ProxyBot m_pb;
	WargusGameState m_currentGameState = null;
	
	public SimpleTacticalLayer(ProxyBot pb) {
		System.out.println("SimpleTacticalLayer constructor started");
		m_pb = pb;
		System.out.println("SimpleTacticalLayer constructor finished");
	}
	
	
	public void run() {
		
		System.out.println("SimpleTacticalLayer started");
	}
	
	public void cycle() throws InterruptedException {
		System.out.println("SimpleTacticalLayer: cycle starts");
		System.out.println("SimpleTacticalLayer: get state...");
		m_pb.lockState();
		m_currentGameState = WargusStateImporter.getGameState(m_pb);
		m_pb.unlockState();
		System.out.println("SimpleTacticalLayer: OK");
		System.out.println("SimpleTacticalLayer: cycle ends");		
	}
	
	
	public void command(BasicOperatorPlan bo) {
		bo.send();
	}	
	
	public WargusGameState getCurrentGameState() {
		return m_currentGameState;
	}
	
	// TODO implement if necessary..
	public void loadFromXML(Element e) { 
		throw new Error("SimpleTacticalLayer.loadFromXML: unimplemented!");
	}
	public void writeXML(XMLWriter w) { 
		throw new Error("SimpleTacticalLayer.writeXML: unimplemented!");
	}

}
